package cn.wolfcode.crm.qo;

import lombok.Getter;
import lombok.Setter;
import org.springframework.stereotype.Component;

import java.util.List;

@Setter
@Getter
public class PageResult<T> {
    private Integer currentPage;
    private Integer pageSize;
    private Integer totalCount;
    private List<T> list;
    private Integer totalPage;
    private Integer nextPage;
    private Integer prevPage;

    public PageResult(Integer currentPage, Integer pageSize, Integer totalCount, List<T> data) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.list = data;
        this.totalPage = totalCount % pageSize == 0 ?
                totalCount / pageSize : totalCount / pageSize + 1;
        this.nextPage = currentPage == totalPage ?
                currentPage : currentPage + 1;
        this.prevPage = currentPage - 1 == 0 ?
                1 : currentPage - 1;
    }
}
